<template>
  <div class="app-container">
    <div class="block">
      <el-row :gutter="20">

        <el-col :span="4">
          <el-select v-model="listQuery.criteria.inBoundType" placeholder="入库类型">
            <el-option label="采购入库" value="0"></el-option>
            <el-option label="退货入库" value="1"></el-option>
          </el-select>
        </el-col>


        <el-col :span="4">
          <el-input v-model="listQuery.criteria.inBoundResponsible" placeholder="客户/供应商"></el-input>
        </el-col>
        <el-col :span="4">
          <el-input v-model="listQuery.criteria.orderNum" placeholder="订单编号"></el-input>
        </el-col>



        <el-col :span="8">
          <el-button type="success" icon="el-icon-search" @click.native="search">搜索</el-button>
          <el-button type="primary" icon="el-icon-refresh" @click.native="reset">重置</el-button>
        </el-col>
      </el-row>
    </div>

    <el-row>
      <el-col :span="20">
        <el-table :data="list" v-loading="listLoading" element-loading-text="Loading" border fit highlight-current-row
          @current-change="handleCurrentChange">


          <el-table-column label="订单号" :span="4">
            <template slot-scope="scope">
              {{ scope.row.orderNum }}
            </template>
          </el-table-column>

          <el-table-column v-if="listQuery.criteria.inBoundType == 0" label="供应商" :span="4">
            <template slot-scope="scope">
              {{ scope.row.inBoundResponsible }}
            </template>
          </el-table-column>
          <el-table-column v-if="listQuery.criteria.inBoundType == 1" label="客户" :span="4">
            <template slot-scope="scope">
              {{ scope.row.inBoundResponsible }}
            </template>
          </el-table-column>
          <el-table-column label="类型" :span="4">
            <template slot-scope="scope">
              {{ scope.row.inBoundType == 0 ? '采购入库' : '退货入库' }}
            </template>
          </el-table-column>

          <el-table-column label="操作" min-width="50px" :span="4">
            <template slot-scope="scope">
              <el-button type="text" size="mini" icon="el-icon-date"
                @click.native="showDetail(scope.row.inBoundTypeId, scope.row.inBoundType)">商品明细</el-button>
              <el-button type="text" size="mini" icon="el-icon-plus" @click.native="inBount(scope.row)">入库</el-button>
            </template>

          </el-table-column>




        </el-table>

        <el-pagination background layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 50, 100, 500]"
          :page-size="listQuery.size" :total="total" :current-page.sync="listQuery.current" @size-change="changeSize"
          @current-change="fetchPage" @prev-click="fetchPrev" @next-click="fetchNext">
        </el-pagination>

      </el-col>
    </el-row>
    <el-dialog title="商品详情" :visible.sync="formVisible" width="70%" :modal-append-to-body="true">
      <el-row>
        <el-col :span="24">
          <el-table :data="goodsDetailList" style="width: 100%;margin-bottom: 20px;" row-key="id" border
            element-loading-text="Loading" fit highlight-current-row :default-expand-all="false">
            <el-table-column label="配图" align="center">
              <template slot-scope="scope">
                <img :src="`${baseUrl}file/getFileByGoodsId/${scope.row.id}?${generNum()}`" alt="加载失败" class="avatar"
                  style="max-height: 50px;max-width: 120px;">
              </template>

            </el-table-column>
            <el-table-column label="商品名称" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template>
            </el-table-column>

            <el-table-column label="商品价格" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.price / 100 }}元</span>
              </template>
            </el-table-column>
            <el-table-column label="价格单位" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.priceUnit }}</span>
              </template>
            </el-table-column>
            <el-table-column label="商品类型" align="center">
              <template slot-scope="scope">
                <span>{{ getTypeValueDict(scope.row.type) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="商品规格" align="center">
              <template slot-scope="scope">
                <el-tag :key="tag" v-for="tag in scope.row.specification" size="mini">
                  {{ tag }}
                </el-tag>
              </template>
            </el-table-column>

            <el-table-column label="商品数量" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.total }}</span>
              </template>
            </el-table-column>

            <el-table-column label="是否存在入库规格" align="center">
              <template slot-scope="scope">
                <el-tag type="success" v-if="scope.row.existGoodsCapacity">存在</el-tag>
                <el-tag type="danger" v-if="!scope.row.existGoodsCapacity">不存在</el-tag>
              </template>

            </el-table-column>

            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button v-if="!scope.row.existGoodsCapacity" type="text" size="mini" icon="el-icon-edit"
                  @click.native="addGoodsCapacity(scope.row)">添加入库规格</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <el-dialog title="添加入库规格" :visible.sync="addGoodsCapacityVisible" :append-to-body="true"
        :modal-append-to-body="true" style="margin-top: 50px;" width="50%">
        <el-form :model="goodsCapacity" label-width="100px"  ref="form">
          <el-row>
            <el-col :span="12">
              <el-form-item label="商品名称" prop="goodsName">
                <el-input v-model="goodsCapacity.goodsName" readonly="true"></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="商品类型" prop="goodsType">
                <el-input :value="getTypeValueDict(goodsCapacity.goodsType)" readonly="true"></el-input>
              </el-form-item>
            </el-col>

            <el-col inline="true" :span="12">
              <el-form-item label="商品规格" prop="specification">
                <el-tag :key="tag" v-for="tag in goodsCapacity.specification">
                  {{ tag }}
                </el-tag>
              </el-form-item>
            </el-col>
            <br>
            <el-col :span="6">
              <el-form-item label="单位容量" prop="capacity">
                <el-input-number :min="1" v-model="goodsCapacity.capacity"></el-input-number>
              </el-form-item>
            </el-col>

          </el-row>
          <el-form-item>
            <el-button type="primary" @click="SaveCapacity">提交</el-button>
            <el-button @click.native="addGoodsCapacityVisible = false">取消</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    </el-dialog>

    <el-dialog title="采购入库" :visible.sync="inBountVisible"
      style="margin-top: 50px;" width="50%">
      <el-form ref="InBoundList" :model="InBoundList" :rules="rules" label-width="80px">
      <el-form-item label="入库仓库" prop="warehouseId">
        <el-select v-model="InBoundList.warehouseId" placeholder="请选择仓库">
          <el-option v-for="item in houseList" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="入库人" prop="inBoundPerson">
        <el-input v-model="InBoundList.inBoundPerson" placeholder="入库人"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="saveInBoundList">提交</el-button>
        <el-button @click.native="inBountVisible = false">取消</el-button>
      </el-form-item>
    </el-form>
    </el-dialog>
  </div>
</template>

<script src="./put.js">
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>
